package com.ruicar.afs.cloud.product.vo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author changyu.gui
 * @version 1.0
 * @date 2020/5/13 23:47
 */
@Data
public class VueVo {

    Integer total;
    List<VueJs> vueJsList = new ArrayList<>();
    List<FormOptionsVo> formOptionsVoList = new ArrayList<>();
    String[] planColumns = new String[vueJsList.size()];

    public VueVo(Map<String, List<VueJs>> map) {
        for (String key : map.keySet()) {
            List<VueJs> jsList = map.get(key);
            this.getFormOptionsVo(jsList, key);
        }
    }

    private void getFormOptionsVo(List<VueJs> jsList, String groupName) {
        List<String> listOne = new ArrayList<>();
        List<String> listTwo = new ArrayList<>();

        int i = 1;
        for (VueJs js : jsList) {
            if (i % 2 == 1) {
                listOne.add(js.getKey());
            } else {
                listTwo.add(js.getKey());
            }
            i++;
        }
        List<List<String>> list = new ArrayList<>();
        list.add(listOne);
        if (listTwo.size() > 0) list.add(listTwo);
        vueJsList.addAll(jsList);
        FormOptionsVo vo = new FormOptionsVo(list, groupName);
        formOptionsVoList.add(vo);
    }
}
